<?php
import("Com.Auth");
import('ORG.Util.Page'); //导入分页类
import('ORG.Net.UploadFile');
import('ORG.Io.Dir');
class UserAction extends Action
//院系
{
	public function _initialize(){
		$this->assign('no',Auth::getno());
    	$this->assign('name',Auth::getname());
    	$this->assign('role',Auth::getrole());
	}
	public function menu(){	//菜单
		$this->assign('role',Auth::getrole()); // 模板发量赋值
		$this->display(); // 输出模板
	}
	public function index(){//主页
		$this->display();
	}
	public function collegedetail(){//院系管理
		 if(Auth::getrole()!='校级管理员')
    		exit('权限不够');
    	else{
		$Department=D("Department");// 实例化模型类
		$count = $Department->count();    //计算总数 
	    $p = new Page ( $count, 20 ); 
		$list=$Department->limit($p->firstRow.','.$p->listRows)->order('id')->select();
		$page = $p->show ();
		$this->assign ( "page", $page );
		$this->assign('list',$list); // 模板发量赋值
		$this->display(); // 输出模板
		}
	}
	public function collegeadd(){//院系添加
		if(Auth::getrole()!='校级管理员')
			exit('权限不够');
		else{
			$Department = D("Department"); // 实例化模型类
			if($Department->Create()){// 创建数据对象
				if($Department->add()){ // 写入数据库
					$this->ajaxReturn(0,'表单数据保存成功！',1);
				}
				else{
					$this->error('数据库写入错误',1);
				}
			}else{
				$this->error($Department->getError(),1);
			}

		}
    } 

	public  function collegedelete(){//院系删除
		if(Auth::getrole()!='校级管理员')
			exit('权限不够');
		else{
			$id=$_POST['id'];
			$department=D("department");
			$department->delete($id);
			$this->redirect('collegedetail');
		}
    } 
	public  function collegeedit(){//院系编辑
		if(Auth::getrole()!='校级管理员')
			exit('权限不够');
		else{
		if(!empty($_GET['id'])) { 
			$c=D("custom1_detail")->getByDepartmentid($_GET['id']);
			$this->assign('c',$c);
            $department=D("department"); 
            $vo=$department->getById($_GET['id']); 
            if($vo) { 
                $this->assign('vo',$vo); 
                $this->display(); 
            }else{ 
                exit('编辑项不存在！'); 
            } 
        }else{ 
            exit('编辑项不存在！'); 
        } 
		}
    } 
    public  function centerlabedit(){//实验中心编辑
		if(Auth::getrole()!='校级管理员')
			exit('权限不够');
		else{
		if(!empty($_GET['id'])) { 
			$c=D("custom1_detail")->getByDepartmentid($_GET['id']);
			$this->assign('c',$c);
            $centerlab=D("centerlab"); 
            $vo=$centerlab->getById($_GET['id']); 
            if($vo) { 
                $this->assign('vo',$vo); 
                $this->display(); 
            }else{ 
                exit('编辑项不存在！'); 
            } 
        }else{ 
            exit('编辑项不存在！'); 
        } 
		}
    } 
    public  function labedit(){//实验室编辑
		if(Auth::getrole()!='校级管理员')
			exit('权限不够');
		else{
		if(!empty($_GET['id'])) { 
			$c=D("custom1_detail")->getByDepartmentid($_GET['id']);
			$this->assign('c',$c);
            $lab=D("lab"); 
            $vo=$lab->getById($_GET['id']); 
            if($vo) { 
                $this->assign('vo',$vo); 
                $this->display(); 
            }else{ 
                exit('编辑项不存在！'); 
            } 
        }else{ 
            exit('编辑项不存在！'); 
        } 
		}
    } 
	public function collegeupdate() { //院系更新
		if(Auth::getrole()!='校级管理员')
    		exit('权限不够');
        $Department=D("Department"); 
		if($Department->Create()){// 创建数据对象
			$Department->save();
			$this->ajaxReturn(0,'表单数据保存成功！',1);
		}else{
			$this->error($Department->getError(),1);
		}
    } 
	public function centerlabdetail(){//实验中心显示
		if(Auth::getrole()!='校级管理员'&&Auth::getrole()!='院系管理员')
    		exit('权限不够');
    	else{
		$centerlab=D("centerlab");// 实例化模型类
		$count = $centerlab->count();    //计算总数 
	    $p = new Page ( $count, 20 ); 
		$list=$centerlab->limit($p->firstRow.','.$p->listRows)->order('id')->select();
		$page = $p->show ();
		$this->assign ( "page", $page );
		$this->assign('list',$list); // 模板发量赋值
		$this->display(); // 输出模板
		}
	}
	//--------------------------------------添加审核页面后台
    public function centerlabaddshenhe(){//实验中心添加确认添加
	
		if(Auth::getrole()!='校级管理员'&&Auth::getrole()!='院系管理员')
			exit('权限不够');
		else{
        $this->assign ( "name", $_POST['name'] );
        $this->assign ( "departmentid", $_POST['departmentid'] );
        $this->assign ( "no", $_POST['no'] );
	    $labname=$_POST['name'];
		$this->assign ( "labname", $labname );
		$department=D("department");// 实例化模型类
		$count2 = $department->count();    //计算总数 
	    $p2 = new Page ( $count, 20 ); 
		$list2=$department->where("id='".$_POST['departmentid']."'")->select();
		$page2 = $p2->show ();
		$this->assign ( "page2", $page2 );
		$this->assign('list2',$list2); // 模板发量赋值

		$info=D("info");// 实例化模型类
		$count1 = $info->count();    //计算总数 
	    $p1 = new Page ( $count, 20 ); 
		$list1=$info->where("no='".$_POST['no']."'")->select();
		$page1 = $p1->show ();
		$this->assign ( "page1", $page1 );
		$this->assign('list1',$list1); // 模板发量赋值
		$this->display(); // 输出模板
		}
    }
	    public function classaddshenhe(){//实验中心添加确认添加
	
		if(Auth::getrole()!='校级管理员'&&Auth::getrole()!='院系管理员'&&Auth::getrole()!='实验中心管理员')
			exit('权限不够');
		else{
        $this->assign ( "name", $_POST['name'] );
        $this->assign ( "centerid", $_POST['centerid'] );
        $this->assign ( "no", $_POST['no'] );
	    $labname=$_POST['name'];
		$this->assign ( "labname", $labname );
		$department=D("centerlab");// 实例化模型类
		$count2 = $department->count();    //计算总数 
	    $p2 = new Page ( $count, 20 ); 
		$list2=$department->where("id='".$_POST['centerid']."'")->select();
		$page2 = $p2->show ();
		$this->assign ( "page2", $page2 );
		$this->assign('list2',$list2); // 模板发量赋值

		$info=D("info");// 实例化模型类
		$count1 = $info->count();    //计算总数 
	    $p1 = new Page ( $count, 20 ); 
		$list1=$info->where("no='".$_POST['no']."'")->select();
		$page1 = $p1->show ();
		$this->assign ( "page1", $page1 );
		$this->assign('list1',$list1); // 模板发量赋值
		$this->display(); // 输出模板
		}
    }
	//-----------------------
    public function centerlabadd(){//实验中心添加
	
		if(Auth::getrole()!='校级管理员'&&Auth::getrole()!='院系管理员')
			exit('权限不够');
		else{
			$Centerlab = D("centerlab"); // 实例化模型类
			if($Centerlab->Create()){// 创建数据对象
				if($Centerlab->add()){ // 写入数据库
					$this->ajaxReturn(0,'表单数据保存成功！',1);
				}
				else{
					$this->error('数据库写入错误',1);
				}
			}
			else{
				$this->error($Centerlab->getError(),1);
			}

		}
    } 
	public  function centerlabdelete(){//实验中心删除
		if(Auth::getrole()!='校级管理员'&&Auth::getrole()!='院系管理员')
			exit('权限不够');
		else{
			$id=$_POST['id'];
			$centerlab=D("centerlab");
			$centerlab->delete($id);
			$this->redirect('centerlabdetail');
		}
    } 
	public function centerlabupdate() { //实验中心更新
		if(Auth::getrole()!='校级管理员'&&Auth::getrole()!='院系管理员')
    		exit('权限不够');
        $centerlab=D("centerlab"); 
		if($centerlab->Create()){// 创建数据对象
			$centerlab->save();
			$this->ajaxReturn(0,'表单数据保存成功！',1);
		}else{
			$this->error($centerlab->getError(),1);
		}
    } 
    public function labdetail(){//实验显示
		if(Auth::getrole()!='校级管理员'&&Auth::getrole()!='院系管理员'&&Auth::getrole()!='实验中心管理员')
    		exit('权限不够');
    	else{
		$lab=D("lab");// 实例化模型类
		$count = $lab->count();    //计算总数 
	    $p = new Page ( $count, 20 ); 
		$list=$lab->limit($p->firstRow.','.$p->listRows)->order('id')->select();
		$page = $p->show ();
		$this->assign ( "page", $page );
		$this->assign('list',$list); // 模板发量赋值
		$this->display(); // 输出模板
		}
	}
    public function labadd(){//实验添加
		if(Auth::getrole()!='校级管理员'&&Auth::getrole()!='院系管理员'&&Auth::getrole()!='实验中心管理员')
			exit('权限不够');
		else{
			$lab = D("lab"); // 实例化模型类
			if($lab->Create()){// 创建数据对象
				if($lab->add()){ // 写入数据库
					$this->ajaxReturn(0,'表单数据保存成功！',1);
				}
				else{
					$this->error('数据库写入错误',1);
				}
			}else{
				$this->error($lab->getError(),1);
			}

		}
    } 
	public  function labdelete(){//实验删除
		if(Auth::getrole()!='校级管理员'&&Auth::getrole()!='院系管理员'&&Auth::getrole()!='实验中心管理员')
			exit('权限不够');
		else{
			$id=$_POST['id'];
			$lab=D("lab");
			$lab->delete($id);
			$this->redirect('labdetail');
		}
    }
	//----------------------------------------------------------------顾的
	//这些代码再后退的功能上存在缺陷，还有判断一些方面需要深究，第一次代码还未修改（4月20号添加）
    public function labdesinsert()//实验室提交维修申请
    {
	$condition['id']=$_POST['id'];
	$condition['amount']=$_POST['amount'];
	$condition['buytime']=$_POST['buytime'];
	$condition['situation']=$_POST['situation'];
	$condition['repair']=$_POST['repair'];
	$condition['introduce']=$_POST['introduce'];
	$condition['pic']=$_POST['pic'];
	$condition['operate']=$_POST['operate'];
    $data=M("Equipment")->add($condition);
  //  echo M("Equipment")->getLastSql(); 
    
	if($data)
	{
		echo "提交成功！页面将在 3 秒后跳转到登陆界面！"; 
		echo("<meta http-equiv=refresh content=3;url=labdetail>");}
	else
	{
		echo "提交失败！页面将在 3 秒后跳转到登陆界面！"; 
		echo("<meta http-equiv=refresh content=3;url=labes>");
	}
    }

	public function MaterialRequire()//申请材料
    {
    	 if(Auth::getrole()!='教师')
    		exit('权限不够');
    	else{
	$condition['id']=$_POST['id'];
	$condition['num']=$_POST['num'];
	$condition['amount']=$_POST['amount'];
	$condition['labroom']=$_POST['labroom'];
	$condition['equ']=$_POST['equ'];
	$condition['labname']=$_POST['labname'];
	$condition['usetime']=$_POST['usetime'];
    $data=M("Buymaterial")->add($condition);
  //  echo M("Equipment")->getLastSql(); 
    
	if($data)
	{
		echo "提交成功！页面将在 3 秒后跳转到登陆界面！"; 
		echo("<meta http-equiv=refresh content=3;url=index>");}
	else
	{
		echo "提交失败！页面将在 3 秒后跳转到登陆界面！"; 
		echo("<meta http-equiv=refresh content=3;url=teacherbuy>");
	}
	
    	}
    }
    
    public function ClassRequire()//申请班级
    {
    	 if(Auth::getrole()!='教师')
    		exit('权限不够');
    	else{
	$condition['name']=$_POST['name'];
	$condition['time']=$_POST['num'];
	$condition['peoplenum']=$_POST['amount'];
	$condition['labid']=$_POST['labid'];
    $data=M("labclass")->add($condition);
  //  echo M("Equipment")->getLastSql(); 
    
	if($data)
	{
		echo "提交成功！页面将在 3 秒后跳转到登陆界面！"; 
		echo("<meta http-equiv=refresh content=3;url=index>");}
	else
	{
		echo "提交失败！页面将在 3 秒后跳转到登陆界面！"; 
		echo("<meta http-equiv=refresh content=3;url=teacherclass>");
	}
    	}
    }
    //-----------------------------------------------------------------------------
	//--------------------维修审核代码
    public function labweixiushenhe(){//实验显示
		if(Auth::getrole()!='校级管理员'&&Auth::getrole()!='院系管理员'&&Auth::getrole()!='实验中心管理员')
    		exit('权限不够');
    	else{
		$lab=D("equipment");// 实例化模型类
		$count = $lab->count();    //计算总数 
	    $p = new Page ( $count, 20 ); 
		$list=$lab->limit($p->firstRow.','.$p->listRows)->order('id')->select();
		$page = $p->show ();
		$this->assign ( "page", $page );
		$this->assign('list',$list); // 模板发量赋值
		$this->display(); // 输出模板
		}
	}
	//-------------------
	//--------------------实验室申请审核代码
    public function labshiyanshishenqing(){//实验显示
		if(Auth::getrole()!='校级管理员'&&Auth::getrole()!='院系管理员'&&Auth::getrole()!='实验中心管理员'&&Auth::getrole()!='管理员')
    		exit('权限不够');
    	else{
		$lab=D("labclass");// 实例化模型类
        $no=Auth::getno();
		$info=M("lab")->where("no='".$no."'")->select();
		$id=$info[0]['id'];
		$count = $lab->count();    //计算总数 
	    $p = new Page ( $count, 20 ); 
		$list=$lab->where("labid='".$id."'")->select();
		$page = $p->show ();
		$this->assign ( "page", $page );
		$this->assign('list',$list); // 模板发量赋值
		$this->display(); // 输出模板
		}
	}
	//-------------------
	public function labupdate() { //实验更新
		if(Auth::getrole()!='校级管理员'&&Auth::getrole()!='院系管理员')
    		exit('权限不够');
        $lab=D("lab"); 
		if($lab->Create()){// 创建数据对象
			$lab->save();
			$this->ajaxReturn(0,'表单数据保存成功！',1);
		}else{
			$this->error($lab->getError(),1);
		}
    } 
	//信息
	public  function  infodetail(){//信息管理
		if(Auth::getrole()!='校级管理员'&&Auth::getrole()!='院系管理员')
    		exit('权限不够');
    	else{
    		if (Auth::getrole()!='校级管理员')
    			$deplist=D("department")->where('id='.Auth::getdepartment())->select();
    		else
				$deplist=D("department")->select();
    	$this->assign('deplist',$deplist);	
    	//$no=$_GET['no'];
		//$name=$_GET['name'];
		//$dname=$_GET['dname'];
		$Model = D("info_detail");
		if(!empty($_GET['no'])||($_GET['name'])||($_GET['dname'])){
			$map['no'] = array('like','%'.$_GET['no'].'%');
			$map['name'] = array('like','%'.$_GET['name'].'%');
			if ($_GET['dname'])
			$map['dname'] = array('eq',$_GET['dname']);
			if (Auth::getrole()!='校级管理员')
			$map['dname']=array('eq',Auth::getdepartmentname());
			$count = $Model->where($map)->count();    //计算总数 
	        $p = new Page ( $count, 20 ); 
	    	$list=$Model->where($map)->limit($p->firstRow.','.$p->listRows)->order('no')->select();
    	}
		else {
			if (Auth::getrole()!='校级管理员')
			$map['dname']=array('eq',Auth::getdepartmentname());
			$count = $Model->where($map)->count();    //计算总数 
	        $p = new Page ( $count, 20 ); 
			$list=$Model->where($map)->limit($p->firstRow.','.$p->listRows)->order('no')->select();			
		}
		$page = $p->show ();
		$this->assign ( "page", $page );
		$this->assign('list',$list); // 模板发量赋值
		$this->assign('role',Auth::getrole());//传值到前台，做权限判断
		$this->display(); // 输出模板
    }
	}
    public function infoadd(){//信息添加_显示
    	if(Auth::getrole()!='校级管理员'&&Auth::getrole()!='院系管理员')
    		exit('权限不够');
    	else{
    	if(Auth::getrole()=='校级管理员'){
    		$rolelist=array("学生","教师","院系管理员","校级管理员");
    		$deplist=D("department")->select();
    	}
    	else {
			$rolelist=array("院系管理员","教师","学生");
	   		$deplist=D("department")->where('id='.Auth::getdepartment())->select();
    	}
	    $this->assign('rolelist',$rolelist);
	    $this->assign('deplist',$deplist);
		$this->display();
    	}
    } 
    public function infoadd_post(){//信息添加_更新
    	if(Auth::getrole()!='校级管理员'&&Auth::getrole()!='院系管理员')
    		exit('权限不够');
    	$info = D("info"); // 实例化模型类
    	if($info->find($_POST['no'])&&$_POST['no'])
    		$this->error('学/工号已存在',1);
    	$data=$info->Create();
		if($data){// 创建数据对象
			$info->add(); // 写入数据库
			$this->ajaxReturn($data,'表单数据保存成功！',1);
		}else{
			$this->error($info->getError(),1);
		}
    } 
   public  function infodelete(){//信息删除
   	if (Auth::getrole()=='校级管理员'||Auth::getrole()=='院系管理员')
   	{
		$no=$_POST['no'];
		$info=D("info");
		$info->delete($no);
		$this->redirect('infodetail');
   	}
		else 
			exit('权限不够');
    } 
    public  function infoedit(){//信息编辑
    	$info=D('info');
    	$role=$info->where('no='.$_GET["no"])->getfield('role');
    	if(Auth::getrole()!='校级管理员'&&Auth::getrole()!='院系管理员')
    		exit('权限不够');
    	else{
    	if(Auth::getrole()=='校级管理员'){
    	$rolelist=array("学生","教师","院系管理员","校级管理员");
    	$deplist=D("department")->select();}
    	else{
    		if ($role=='校级管理员')
    			exit('权限不够');
    		else {
				$rolelist=array("院系管理员","教师","学生");
				$deplist=D("department")->where('id='.Auth::getdepartment())->select();
    		}
    		}
    	}
    	//$deplist=D("department")->select();
    	$this->assign('rolelist',$rolelist);
    	$this->assign('deplist',$deplist);	
		if(!empty($_GET['no'])) { 
            $info=D("info"); 
            $vo=$info->getByno($_GET['no']); 
            if($vo) { 
                $this->assign('vo',$vo); 
                $this->display(); 
            }else{ 
                exit('编辑项不存在！'); 
            } 
        }else{ 
            exit('编辑项不存在！'); 
        } 
    }
    public function infoupdate() { //信息更新
    	if(Auth::getrole()!='校级管理员'&&Auth::getrole()!='院系管理员')
    		exit('权限不够');
    	$info=D("info");
    	$info->where('no='.$_POST["no"])->
    	setfield(array('name','role','departmentid'),array($_POST['name'],$_POST['role'],$_POST['departmentid']));
       	$info->save(); 
        $this->redirect('infodetail');        
    } 
    public function infoimport(){//批量导入
    	if(Auth::getrole()!='校级管理员'&&Auth::getrole()!='院系管理员')
    		exit('权限不够');
    	else{
    	if(Auth::getrole()=='校级管理员'){
    		$rolelist=array("学生","教师","院系管理员","校级管理员");
    		$deplist=D("department")->select();
    	}
    	else {
			$rolelist=array("学生","教师","院系管理员");
	   		$deplist=D("department")->where('id='.Auth::getdepartment())->select();
    	}
	    $this->assign('rolelist',$rolelist);
	    $this->assign('deplist',$deplist);
		$this->display();
    	}
    }
    public function infoimport_result(){//批量导入
    	$upload = new UploadFile(); // 实例化上传类
        $upload->maxSize=-1;
		if (!file_exists('./File/temp/'))
			mkdir('./File/temp/');
        $upload->savePath ='./File/temp/';
        $upload->allowExts = array('xls',);  
      	$upload->saveRule=time;
		if (!$upload->upload()) {
            //捕获上传异常
            $this->error($upload->getErrorMsg());
        } else {
            //取得成功上传的文件信息
            $uploadList = $upload->getUploadFileInfo();
            $dir = $uploadList[0]['savepath'].$uploadList[0]['savename'];
            Vendor('Excel.reader');                         //加载第三方类
	    	$data = new Spreadsheet_Excel_Reader();
			$data->setOutputEncoding('utf-8');
			$data->read($dir); 
			for ($i =$_POST['hang'],$j=0; $i <= $data->sheets[0]['numRows']; $i++,$j++){
				$list[$i]['name']=$_POST['name']=trim($data->sheets[0]['cells'][$i][$_POST['lname']]);
				$list[$i]['no']=$_POST['no']=trim($data->sheets[0]['cells'][$i][$_POST['lno']]);
				$info=M('info');
				if($list[$i]['name']==''||$list[$i]['no']==''){
					$list[$i]['mes']='姓名或学号为空';
					$list[$i]['success']=0;
					continue;
				}
				if($info->create()){
					if($info->add()){
						$list[$i]['mes']='添加成功';
						$list[$i]['success']=1;
					}
					else{
						$list[$i]['mes']='已存在该用户不必重复导入';
						$list[$i]['success']=0;
					}
				}
				else{
					$list[$i]['mes']=$info->getError();
					$list[$i]['success']=0;
				}
			}
			$this->assign('list',$list);
            unlink($dir);
            $this->display();
        } 
   //课程       
    }
	public function coursedetail(){//课程管理
		if (Auth::getrole()=='访客')
			$this->redirect('auth/logon');
		if (Auth::getrole()=='学生'){
			exit('权限不够');
		}
		else {
			if (Auth::getrole()!='校级管理员')
    			$deplist=D("department")->where('id='.Auth::getdepartment())->select();
    		else
				$deplist=D("department")->select();
	    	$this->assign('deplist',$deplist);
	    	$name=$_GET['name'];
			$dname=$_GET['dname'];
			$Model = D("course_detail");
		if(!empty($_GET['name'])||($_GET['number'])||($_GET['dname'])){
			$map['name'] = array('like',$_GET['name'].'%');
			$map['number'] = array('like',$_GET['number'].'%');
			if ($_GET['dname'])
			$map['dname'] = array('eq',$_GET['dname']);
			if (Auth::getrole()!='校级管理员')
			$map['dname']=array('eq',Auth::getdepartmentname());
	    	$count = $Model->where($map)->count();    //计算总数 
	        $p = new Page ( $count, 20 ); 
	    	$list=$Model->where($map)->limit($p->firstRow.','.$p->listRows)->order('id')->select();
    	}
		else {
			if (Auth::getrole()!='校级管理员')
			$map['dname']=array('eq',Auth::getdepartmentname());
			$count = $Model->count();    //计算总数 
	        $p = new Page ( $count, 20 ); 
			$list=$Model->where($map)->limit($p->firstRow.','.$p->listRows)->order('id')->select();
		}
		foreach($list as $k=>$v){
			$Form = D('tcrelate');
			$map1['courseid']=array('eq',$v['id']);
			$map1['no']=array('eq',Auth::getno());
			$map2['courseid']=array('eq',$v['id']);
			$map2['no']=array('eq',Auth::getno());
			$map2['approve']=array('eq',1);
			if($Form->where($map1)->select())
				$list[$k]["isselect"]=true;
			else 
				$list[$k]["isselect"]=false;
			if (Auth::getrole()=='校级管理员'||Auth::getrole()=='院系管理员'||$Form->where($map2)->select())
				$list[$k]["select"]=true;
			else
				$list[$k]["select"]=false;
		}
		$page = $p->show ();
		$this->assign ( "page", $page );
    	$this->assign('list',$list); // 模板发量赋值
    	$this->assign('role',Auth::getrole());// 模板发量赋值
		$this->display(); // 输出模板
	}
}
	public function courseadd_post(){//课程添加
		$course = D("course"); // 实例化模型类
		$_POST['pv']=0;
		$_POST['time']=date('Y-m-d H:i:s');
		if($course->Create()){// 创建数据对象
			if($course->add()){ // 写入数据库
				$this->ajaxReturn(0,'表单数据保存成功！',1);
			}
			else{
				$this->error('数据库写入错误',1);
			}
		}else{
			$this->error($course->getError(),1);
		}
	}
	public function courseadd(){//课程添加
		if(Auth::getrole()!='校级管理员'&&Auth::getrole()!='院系管理员')
    		exit('权限不够');
    	else{
    		if (Auth::getrole()!='院系管理员')
    			$deplist=D("department")->select();
    		else 
    		$deplist=D("department")->where('id='.Auth::getdepartment())->select();	
    	}
		//$deplist=D("department")->select();
    	$this->assign('deplist',$deplist);
		$this->display();
    } 
	public  function coursedelete(){//课程删除
		if(Auth::getrole()!='校级管理员'&&Auth::getrole()!='院系管理员')
    		exit('权限不够');
    	else{
		 $id=$_POST['id'];
		 $tcrelate=D('tcrelate');
		 $tcrelate->where('courseid='.$_POST['id'])->delete();
		 $course=D("course");
		 $course->delete($id);
		 $this->redirect('coursedetail');
    	}
    } 
	public  function courseedit(){//课程编辑
		$Form = D('tcrelate');
		$map['no']=array('eq',Auth::getno());
		$map['courseid']=array('eq',$_GET['id']);
		$map['approve']=array('eq',1);
		if(Auth::getrole()!='校级管理员'&&Auth::getrole()!='院系管理员'&&!($Form->where($map)->select()))
    		exit('权限不够');
    	else{
    		if (Auth::getrole()!='校级管理员')
    			$deplist=D("department")->where('id='.Auth::getdepartment())->select();
    		else
				$deplist=D("department")->select();
		$clist=D("custom_detail")->where('courseid='.$_GET['id'])->select();
		$this->assign('clist',$clist);
    	$this->assign('deplist',$deplist);	
		if(!empty($_GET['id'])) { 
            $course=D("course_detail"); 
            $vo1=$course->getById($_GET['id']); 
            if($vo1) { 
            	$this->assign('id',$_GET['id']);
                $this->assign('vo1',$vo1); 
                $this->assign('number',$vo1['number']);
                $this->assign('coursename',$vo1['name']);
                $this->assign('departmentid',$vo1['departmentid']);
                $this->display(); 
            }else{ 
                exit('编辑项不存在！'); 
            } 
        }else{ 
            exit('编辑项不存在！'); 
        } 
    } 
	}
	public function courseapprove()//课程认证_显示
	{
		if(Auth::getrole()=='校级管理员')
			$list=D('tcrelate_detail')->select();
		elseif (Auth::getrole()=='院系管理员')
			$list=D('tcrelate_detail')->where('departmentid='.Auth::getdepartment())->select();
		else 
			exit('权限不够');
		foreach($list as $k=>$v){
			$Form = D('tcrelate');
			$map1['id']=array('eq',$v['id']);
			$map1['approve']=array('eq',1);
			if($Form->where($map1)->select())
				$list[$k]["select"]=true;
			else
				$list[$k]["select"]=false;
		}
		$this->assign('list',$list);
		//dump($list);
		$this->display();
	}
	public function approve()//课程认证_更新
	{
		$tcrelate=D('tcrelate');
		$_POST['approve']=1;
		$tcrelate->create();
		$tcrelate->save();
		$this->redirect('courseapprove');
	}
    public function course(){//tc关系
	    $map['courseid']=$_POST['id'];
	    $map['no']=Auth::getno();
	    $Form=D('tcrelate');
	    if($Form->where($map)->select())
			$Form->where($map)->delete();
		else 
			$Form->add($map);
		$this->redirect('coursedetail');
    }
	public function courseupdate() { //课程更新
		$course = D("course"); // 实例化模型类
		if($_POST['number']!=$course->where('id='.$_POST['id'])->getField('number')&&$course->where('number='.$_POST['number'])->getField('id'))
			$this->error('课程序号已存在!',1);
		else
			if($_POST['choose']==1)
				$_POST['url']=$_POST['url1'];
			elseif ($_POST['choose']==2)
				$_POST['url']=$_POST['url2'];
			if ($_POST['excellent']=='')
			$_POST['excellent']=0;
			$course->create();
			$course->save();
			//dump($_POST);
			$this->ajaxReturn(0,'表单数据保存成功！',1);
    }
	public function coursesxupdate() { 
		$coursesx = D("coursesx"); // 实例化模型类
		if($_POST['url1'])
		$_POST['url']=$_POST['url1'];
		elseif ($_POST['url2'])
		$_POST['url']=$_POST['url2'];
		$coursesx->create();
		$coursesx->save();
		//dump($coursesx);
		//$_POST['time']=date('Y-m-d H:i:s'); 
		/*if($coursesx->create()){// 创建数据对象
			$coursesx->save();// 写入数据库
			$this->ajaxReturn(0,'表单数据保存成功！',1);
		}else{
			$this->error($coursesx->getError(),1);
		}*/     
    }
    public function alterpw(){//修改密码界面
    	$this->display();
    }
    public function alterpw_post()//修改密码
    {
    	$info=D('info');
    	$pw=$info->where('no='.Auth::getno())->getfield('password');
    	if ($_POST['password1']!=$pw)
    		$this->error('原始密码不对！',1);
    	elseif ($_POST['password2']!=$_POST['password3'])	
    		$this->error('两次输入不一致！',1);
    	elseif (!$_POST['password2'])
    		$this->error('修改的密码不能为空！',1);
    	else
    		$info->where('no='.Auth::getno())->setfield('password',$_POST['password2']);
    	$this->success(); 		
    }
//教学班
public function classdetail()//教学班界面
    {
    	if (Auth::getrole()=='访客')
			$this->redirect('auth/logon');
		if (Auth::getrole()=='学生')
			exit('权限不够');
    	$form=D('class_detail');
    	$count=$form->where('no='.Auth::getno())->count();
    	$p=new Page($count, 20);
    	$list=$form->where('no='.Auth::getno())->limit($p->firstRow.','.$p->listRows)->select();
    	$page=$p->show();
    	$this->assign ( "page", $page );
    	$this->assign ( "name", Auth::getname());
		$this->assign('list',$list); // 模板发量赋值
		$this->display(); // 输出模板
    }
    public function classadd()//教学班添加界面
    {	
    	if (Auth::getrole()=='访客')
			$this->redirect('auth/logon');
		if (Auth::getrole()=='学生')
			exit('权限不够');
    	$form=D('tcrelate_detail');
    	$list=$form->where('no='.Auth::getno())->select();
   		$this->assign('no',Auth::getno()); // 模板发量赋值
    	$this->assign('list',$list); // 模板发量赋值
		$this->display(); // 输出模板
    }
	public function class_add()//教学班添加
    {	
    	$_POST['id']=trim($_POST['id']);
    	$class = D("class"); // 实例化模型类
    	if($class->find($_POST['id'])&&$_POST['id'])
    		$this->error('教学班已存在',1);
		if($class->Create()){// 创建数据对象
			$class->add(); // 写入数据库
			if (!file_exists('./File/class/'.$_POST['id'].'/'))
			mkdir('./File/class/'.$_POST['id'].'/');
			$this->ajaxReturn(0,'表单数据保存成功！',1);
			
		}else{
			$this->error($class->getError(),1);
		}
    } 
    public  function classdelete(){//教学班删除
		if(Auth::getrole()!='校级管理员')
			exit('权限不够');
		else{
			$class=D("class");
			$class->delete($_POST['id']);
			Dir::delDir('./File/class/'.$_POST['id']);
			$this->redirect('classdetail');
		}
    } 
	public  function classedit(){//教学班编辑
		if(Auth::getrole()!='校级管理员')
			exit('权限不够');
		else{
		if(!empty($_GET['id'])) { 
            $class=D("class_detail"); 
            $vo=$class->getById($_GET['id']); 
            if($vo) { 
                $this->assign('vo',$vo); 
                $this->display(); 
            }else{ 
                exit('编辑项不存在！'); 
            } 
        }else{ 
            exit('编辑项不存在！'); 
        } 
		}
    } 
	public function classupdate() { //教学班更新
        $class=D("class"); 
        $_POST['id']=trim($_POST['id']);
        if (!$_POST['id'])
        	$this->error('不能为空',1);
        if (file_exists('./File/class'.'/'.$_POST['id'].'/'))
    		$this->error('教学班已存在',1);
    		$class-> where('id='.$_POST['id1'])->setField('id',$_POST['id']);
			$dir='./File/class/';
    		rename($dir.$_POST['id1'],$dir.$_POST['id']);
			$this->ajaxReturn(0,'表单数据保存成功！',1);
    }
    public function classfile()//教学班文件夹
    {
		if (Auth::getrole()=='访客')
			$this->redirect('auth/logon');
		if (Auth::getrole()=='学生')
			exit('权限不够');
   			$id=$_GET['id'];
	   		$form=D('save');
	   		$map['classid']=array('eq',$_GET['id']);
			$count=$form->where($map)->count();
			$p=new Page($count, 20);
			$list=$form->where($map)->limit($p->firstRow.','.$p->listRows)->order('id')->select();
   		$page = $p->show ();
   		$this->assign ( 'page', $page );
   		$this->assign('id',$_GET['id']);
   		$this->assign('list',$list);
   		$this->display(); // 输出模板
    } 

   public function savepath()//文件夹保存路径
   {
   		if (Auth::getrole()=='访客')
			$this->redirect('auth/logon');
		if (Auth::getrole()=='学生')
			exit('权限不够');
   		if (!file_exists('./File/class/'.$_GET['id'].'/'))
			mkdir('./File/class/'.$_GET['id'].'/');
    	$this->assign('id',$_GET['id']); // 模板发量赋值
		$this->display(); // 输出模板	
   }
 	public function save_add()//添加文件夹保存路径
   {	
   		if (Auth::getrole()=='访客')
			$this->redirect('auth/logon');
		if (Auth::getrole()=='学生')
			exit('权限不够');
   	 	$_POST['pname']=trim($_POST['pname']);
		//$_POST['pname']=$_POST['path'];
   		//$_POST['path']='/File/class'.'/'.$_POST['classid'].'/'.$_POST['path'].'/';
  		$save = D("save"); // 实例化模型类
  		if (!file_exists('./File/class'.'/'.$_POST['classid'].'/'.$_POST['pname'].'/'))
  		{
  			$filename='./File/class'.'/'.$_POST['classid'].'/'.$_POST['pname'].'/';
  			mkdir(iconv("UTF-8", "GBK",$filename));
  		}
		elseif ($_POST['pname']) 
			$this->error('文件夹已存在',1);
		if($save->Create()){// 创建数据对象
			$save->add(); // 写入数据库
			$this->ajaxReturn(0,'表单数据保存成功！',1);
			
		}else{
			$this->error($save->getError(),1);
		}
   }
	public function addstudent()//教学班添加学生
	{    	
	    if(Auth::getrole()=='学生'||Auth::getrole()=='访客')
	    		exit('权限不够');
	    else{	
			$deplist=D("department")->select();
	    	$this->assign('deplist',$deplist);	
	    	//$no=$_GET['no'];
			//$name=$_GET['name'];
			//$dname=$_GET['dname'];
			$Model = D("info_detail");
			if(!empty($_GET['no'])||($_GET['name'])||($_GET['dname'])){
				$map['no'] = array('like','%'.$_GET['no'].'%');
				$map['name'] = array('like','%'.$_GET['name'].'%');
				if ($_GET['dname'])
				$map['dname'] = array('eq',$_GET['dname']);
				//if (Auth::getrole()!='校级管理员')
				//$map['dname']=array('eq',Auth::getdepartmentname());
				$map['role'] = array('eq','学生');
				$count = $Model->where($map)->count();    //计算总数 
		        $p = new Page ( $count, 50 ); 
		    	$list=$Model->where($map)->limit($p->firstRow.','.$p->listRows)->order('no')->select();
	    	}
			else {
				//if (Auth::getrole()!='校级管理员')
				//$map['dname']=array('eq',Auth::getdepartmentname());
				$map['role'] = array('eq','学生');
				$count = $Model->where($map)->count();    //计算总数 
		        $p = new Page ( $count, 50 ); 
				$list=$Model->where($map)->limit($p->firstRow.','.$p->listRows)->order('no')->select();
			}
	   		 foreach($list as $k=>$v){
				$Form = D('screlate');
				$map1['classid']=array('eq',$_GET['id']);
				$map1['no']=array('eq',$v['no']);
				if($Form->where($map1)->select())
					$list[$k]["isselect"]=true;
				else
					$list[$k]["isselect"]=false;
			}
			$page = $p->show ();
			$this->assign ( "page", $page );
			$this->assign('list',$list); // 模板发量赋值
			$this->assign('id',$_GET['id']); 
			$this->assign('role',Auth::getrole());//传值到前台，做权限判断
			$this->display(); // 输出模板	
	    }
    }
	public function student_add()//教学班添加学生
    {	
    	
    	foreach($_POST['no'] as $k=>$v){    	
    	$screlate = M("screlate"); // 实例化模型类
    	$data['no']=$v;
    	$data['classid']=$_POST['classid'];
    	//$screlate->Create();
    	//$screlate->add();
    	//dump($screlate);
		$screlate->add($data); // 写入数据库		
		}
		$this->redirect('addstudent',array('id'=>$_POST[classid]));
    } 
    public function deletestudent()//教学班删除学生
    {
     if(Auth::getrole()=='学生'||Auth::getrole()=='访客')
    		exit('权限不够');
		$Model = D("screlate_detail");
		if(!empty($_GET['no'])||($_GET['name'])){
			$map['no'] = array('like','%'.$_GET['no'].'%');
			$map['name'] = array('like','%'.$_GET['name'].'%');
			$map['classid'] = array('eq',$_GET['id']);
			$count = $Model->where($map)->count();    //计算总数 
	        $p = new Page ( $count, 50 ); 
	    	$list=$Model->where($map)->limit($p->firstRow.','.$p->listRows)->order('no')->select();
    	}
		else {
			$map['classid'] = array('eq',$_GET['id']);
			$count = $Model->where($map)->count();    //计算总数 
	        $p = new Page ( $count, 50 ); 
			$list=$Model->where($map)->limit($p->firstRow.','.$p->listRows)->order('no')->select();
		}
		$page = $p->show ();
		$this->assign ( "page", $page );
		$this->assign('list',$list); // 模板发量赋值
		$this->assign('id',$_GET['id']); 
		$this->assign('role',Auth::getrole());//传值到前台，做权限判断
		$this->display(); // 输出模板
    }
    public function student_delete()//教学班删除学生
    {	
    	foreach($_POST['id'] as $k=>$v){    	
    	$screlate = D("screlate"); // 实例化模型类
    	//$screlate->Create();
    	//$screlate->add();
    	//dump($screlate);
		$screlate->delete($v); 	
		}
		$this->redirect('deletestudent',array('id'=>$_POST[classid]));
    } 
	public function studentupload() {//学生上传
		if (Auth::getrole()=='访客')
			$this->redirect('auth/logon');
		if (!empty($_GET['id'])){
		$list=D('save')->where('classid='.$_GET['id'])->select();
		$this->assign('classid',$_GET['id']);
		$this->assign('list',$list);
		$this->display();
		 if (!empty($_FILES)) { 
            //如果有文件上传 上传附件 
            $this->_studentupload(); 
            //$this->forward(); 
		}
		}
		else 
			exit('课程不存在');       
    } 
	public function _studentupload() {    
		$save=D('save');
		$pname=$save->where('id='.$_POST['id'])->getField('pname');
		$filename=$_FILES['image']['name']; //单独输出filename是可以得出值的
		$filetype=end(explode(".",$filename)); 
		$_FILES['image']['name']=Auth::getno().'-'.Auth::getname().'.'.$filetype;
        $upload = new UploadFile(); // 实例化上传类
        $upload->maxSize=-1;
        //$upload->savePath =iconv("UTF-8", "GBK", './File/class/'.$_POST['id'].'/'.$_POST['pname'].'/');
        //echo iconv("UTF-8", "GBK", './File/class/'.$_POST['id'].'/'.$_POST['pname'].'/');
        $upload->savePath ='./File/class/'.$_POST['classid'].'/'.$pname.'/';
      	$upload->allowExts=array(); 
      	//$upload->saveRule=time;
		if (!$upload->upload()) {
            //捕获上传异常
            $this->error($upload->getErrorMsg());
        } else {
            //取得成功上传的文件信息
            $uploadList = $upload->getUploadFileInfo();
            $_POST['name'] = $uploadList[0]['name'];
            //$_POST['savename'] = $uploadList[0]['savename'];
            $_POST['extension'] = $uploadList[0]['extension'];
            $_POST['path'] = $uploadList[0]['savepath'];
            $_POST['size'] = $uploadList[0]['size'];
        $model = M('work');
        $map['name']=$_POST['name'];
        $map['classid']=$_POST['classid'];
        $map['saveid']=$_POST['id'];
        if($model->where($map)->count())
        	$model->where($map)->delete();
        //保存当前数据对象
        $data['nname'] = Auth::getname();
        $data['no']=Auth::getno();
        $data['name'] = $_POST['name'];
        $data['savename'] = Auth::getno().'-'.Auth::getname().'.'.$_POST['extension'];
        $data['size']= $_POST['size'];
        $data['path']= substr ($_POST['path'], 1);
        $data['saveid']= $_POST['id'];
       	//$data['downloadno']= 0;
        $data['classid']= $_POST['classid'];
        $data['time'] = date('Y-m-d H:i:s');
        $list = $model->add($data);
        if ($list !== false) { 
            $this->success('上传成功！'); 
        } else { 
            $this->error('上传失败!'); 
        }
        } 
   }
 	public function handin()//作业提交
    {
    	if (Auth::getrole()=='访客')
			$this->redirect('auth/logon');
    	$form=D('screlate_detail');
    	$list=$form->where('no='.Auth::getno())->select();
    	$this->assign('list',$list);
    	$this->display();
    }
    public function workdetail()//教师
    {	
    	if (Auth::getrole()=='访客')
			$this->redirect('auth/logon');
		if (Auth::getrole()=='学生')
			exit('权限不够');
    	$save=D('save');
    	$pname=$save->where('id='.$_GET['p'])->getField('pname');
    	$work=D('work');
    	$list=$work->where('saveid='.$_GET['p'])->select();
   	 	foreach($list as $k=>$v){
			$work = D('work');
			if($work->where('id='.$v['id'])->getField('text'))
				$list[$k]["a"]=true;
			else
				$list[$k]["a"]=false;
		}
    	$this->assign('classid',$_GET['id']);
    	$this->assign('p',$_GET['p']);
    	$this->assign('pname',$pname);
    	$this->assign('list',$list);
    	$this->display();
    }
 public function work_detail()//学生
    {	
		if (Auth::getrole()!='学生')
			exit('权限不够');
    	$save=D('save');
    	$pname=$save->where('id='.$_GET['p'])->getField('pname');
    	$work=D('work_detail');
    	$list=$work->where('no='.Auth::getno())->select();
    	$this->assign('classid',$_GET['id']);
    	$this->assign('p',$_GET['p']);
    	$this->assign('pname',$pname);
    	$this->assign('list',$list);
    	$this->display();
    }
     public function pathedit()
   {
   	if (Auth::getrole()=='访客')
			$this->redirect('auth/logon');
		if (Auth::getrole()=='学生')
			exit('权限不够');
   	if(!empty($_GET['id'])) { 
            $save=D("save"); 
            $vo=$save->getByid($_GET['id']); 
            if($vo) { 
            	$this->assign('id',$vo['classid']);
                $this->assign('vo',$vo); 
                $this->display(); 
            }else{ 
                exit('编辑项不存在！'); 
            } 
        }else{ 
            exit('编辑项不存在！'); 
        } 
   }
    public function pathupdate() { 
    	if (Auth::getrole()=='访客')
			$this->redirect('auth/logon');
		if (Auth::getrole()=='学生')
			exit('权限不够');
    	$_POST['pname']=trim($_POST['pname']);
    	$save=D("save");
    	if($save->create()){
    		if (file_exists('./File/class'.'/'.$_POST['classid'].'/'.$_POST['pname'].'/'))
    		$this->error('文件夹已存在',1);
    		$save->save(); 
    		$dir='./File/class/'.$_POST['classid'].'/';
    		//mkdir(iconv("UTF-8", "GBK",$filename));
    		//iconv("UTF-8", "GBK", $filename);
    		rename(iconv("UTF-8", "GBK",$dir.$_POST['path']),iconv("UTF-8", "GBK",$dir.$_POST['pname']));
			$this->success('保存成功',1);
    	}
       	else{
       		$this->error($save->getError(),1);
       	}      
    } 
    public  function pathdelete(){
    	if (Auth::getrole()=='访客')
			$this->redirect('auth/logon');
		if (Auth::getrole()=='学生')
			exit('权限不够');
		$id=$_POST['id'];
		$save=D("save");
		//$a=$save->where('id='.$_POST['id'])->getfield(savename);
		if ($_POST['pname'])
		Dir::delDir(iconv("UTF-8", "GBK",'./File/class/'.$_POST['classid'].'/'.$_POST['pname']),$subdir=true);
		//else 
		$save->delete($id);
		$this->redirect('classfile',array('id'=>$_POST['classid']));
    } 
    public  function workdelete(){
    	if (Auth::getrole()=='访客')
			$this->redirect('auth/logon');
		$work=D("work");
		$name=$work->where('id='.$_POST['id'])->getField('name');
		$filename=iconv("UTF-8", "GBK",'./File/class/'.$_POST['classid'].'/'.$_POST['pname'].'/'.$name);
		@unlink($filename);
		//@unlink('./File/class/'.$_POST['classid'].'/'.$_POST['pname'].'/'.$name);
		$work->delete($_POST['id']);
		$this->redirect('workdetail',array('id'=>$_POST['classid'],'p'=>$_POST['p']));
    } 
    public function filedownload()
    {
    	Vendor('php_zip.zip');                         //加载第三方类
		$zip = new PHPZip(); 
		$filename=iconv("UTF-8", "GBK",'./File/class/'.$_POST['classid'].'/'.$_POST['pname']);
		$zip -> createZip($filename, $_POST[pname].'.zip',1);
		//$zip -> downloadZip("./File/class/123/1", "1.zip");//自动下载
    }
 	public function addcustom()
    {
    	$this->assign('courseid',$_GET['id']);
    	$this->display();
    }
	public function custom_add()
	{	
		$custom = D('custom'); // 实例化模型类
		$_POST['time']=date('Y-m-d H:i:s'); 
		$_POST['pv']=0;
		$_POST['no']=Auth::getno();
		//$custom->create();
		//$custom->add();
		//$this->redirect('course/course',array('id'=>$_POST['courseid'],'id'=>$_POST['id']));
		if($custom->create()){
			if($custom->add())
				$this->success('表单提交成功');
			else
				$this->error('数据库插入错误');
		}
		$this->error($custom->getError());
	}
	public function customedit()
	{	
		if(!empty($_POST['id'])) { 
            $vo=D("custom_detail")->getById($_POST['id']); 
            if($vo) { 
                $this->assign('vo',$vo); 
                $this->display(); 
            }else{ 
                exit('编辑项不存在！'); 
            } 
        }else{ 
            exit('编辑项不存在！'); 
        } 
	}
public function customdelete()
	{	
		if(!empty($_POST['id'])) { 
            D("custom")->delete($_POST['id']); 
               $this->redirect('courseedit',array('id'=>$_POST['courseid']));
        }else{ 
            exit('删除项不存在！'); 
        } 
	}
	public function customupdate() { 
		$custom = D("custom"); // 实例化模型类
		$_POST['time']=date('Y-m-d H:i:s'); 
		$_POST['pv']=0;
		$_POST['no']=Auth::getno();
		if($custom->create()){// 创建数据对象
			$custom->save();// 写入数据库
			$this->ajaxReturn(0,'表单数据保存成功！',1);
		}else{
			$this->error($custom->getError(),1);
		}          
    }

	public function adddcustom()
    {
    	if (D('custom1')->where('departmentid='.$_GET['id'])->count())
    	exit('院系主页已存在！');
    	$this->assign('departmentid',$_GET['id']);
    	$this->display();
    }
	public function dcustom_add()
	{	
		$custom = D('custom1'); // 实例化模型类
		$_POST['time']=date('Y-m-d H:i:s'); 
		$_POST['pv']=0;
		$_POST['no']=Auth::getno();
		//$custom->create();
		//$custom->add();
		//$this->redirect('depart/depart',array('id'=>$_POST['departid'],'id'=>$_POST['id']));
		if($custom->create()){
			if($custom->add())
				$this->success('表单提交成功');
			else
				$this->error('数据库插入错误');
		}
		$this->error($custom->getError());
	}
	public function dcustomedit()
	{	
		if(!empty($_POST['id'])) { 
            $vo=D("custom1_detail")->getById($_POST['id']); 
            if($vo) { 
                $this->assign('vo',$vo); 
                $this->display(); 
            }else{ 
                exit('编辑项不存在！'); 
            } 
        }else{ 
            exit('编辑项不存在！'); 
        } 
	}
	public function dcustomdelete()
	{	
		if(!empty($_POST['id'])) { 
            D("custom1")->delete($_POST['id']); 
               $this->redirect('departedit',array('id'=>$_POST['departid']));
        }else{ 
            exit('删除项不存在！'); 
        } 
	}
	public function dcustomupdate() { 
		$custom = D("custom1"); // 实例化模型类
		$_POST['time']=date('Y-m-d H:i:s'); 
		$_POST['pv']=0;
		$_POST['no']=Auth::getno();
		if($custom->create()){// 创建数据对象
			$custom->save();// 写入数据库
			$this->ajaxReturn(0,'表单数据保存成功！',1);
		}else{
			$this->error($custom->getError(),1);
		}          
    }
    public function remark()
    {
    	$vo=D('work')->getById($_GET['id']); 
    	$this->assign('vo',$vo);
    	$this->display();
    }
	public function workremark() { 
		$work = D("work"); // 实例化模型类
		if($work->create()){// 创建数据对象
			$work->save();// 写入数据库
			$this->ajaxReturn(0,'表单数据保存成功！',1);
		}else{
			$this->error($work->getError(),1);
		}          
    }
}
?>